package vistas;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import controller.ControllerPrincipal;

import beans.EntidadBean;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class DetalleCliente extends BaseJFrame {

	protected JLabel LNombre;
	protected JTextField jTextIVA;
	protected JButton btnModificar;
	protected JTextField JTextRS;
	protected JTextField jTextCuil;
	protected JLabel LDni;
	protected JLabel labelTitulo;
	protected JLabel LApellido;
	protected JButton btnSalir;
	protected JButton btnEliminar;
	protected EntidadBean cliente;
	protected JButton jButton2;
	protected JButton btnNuevaCond;

	public DetalleCliente() {
		super();
		initGUI();
		deshabilitarCampos();
	}

	public DetalleCliente(EntidadBean cb) {
		super();
		this.cliente = cb;
		initGUI();
		setData();
		deshabilitarCampos();
	}

	// los detalles vana ser pasados todos a un padre con comportamiento comun

	protected void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				this.setSize(522, 406);
			}
			{
				LApellido = new JLabel();
				getContentPane().add(LApellido);
				LApellido.setText("Razon Social:");
				LApellido.setBounds(11, 79, 116, 16);
			}
			{
				LNombre = new JLabel();
				getContentPane().add(LNombre);
				LNombre.setText("Cuil:");
				LNombre.setBounds(12, 50, 96, 21);
			}
			{
				labelTitulo = new JLabel();
				getContentPane().add(labelTitulo);
				labelTitulo.setText("Detalle de Cliente");
				labelTitulo.setBounds(98, 12, 202, 19);
				labelTitulo.setFont(new java.awt.Font("Segoe UI", 1, 16));
			}
			{
				LDni = new JLabel();
				getContentPane().add(LDni);
				LDni.setText("Condicion IVA:");
				LDni.setBounds(12, 108, 86, 16);
			}
			{
				jTextCuil = new JTextField();
				getContentPane().add(jTextCuil);
				jTextCuil.setBounds(98, 50, 250, 23);
			}
			{
				JTextRS = new JTextField();
				getContentPane().add(JTextRS);
				JTextRS.setBounds(98, 77, 247, 23);
			}
			{
				jTextIVA = new JTextField();
				getContentPane().add(jTextIVA);
				jTextIVA.setBounds(98, 106, 247, 23);
			}
			{
				btnModificar = new JButton();
				getContentPane().add(btnModificar);
				btnModificar.setText("Modificar");
				btnModificar.setBounds(386, 57, 98, 34);
				btnModificar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						ModificacionCliente frm = new ModificacionCliente(
								cliente);
						frm.setLocationRelativeTo(null);
						frm.setVisible(true);
						_exit();

					}
				});
			}
			{
				btnEliminar = new JButton();
				getContentPane().add(btnEliminar);
				btnEliminar.setText("Eliminar");
				btnEliminar.setBounds(386, 99, 97, 35);
				btnEliminar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							ControllerPrincipal.getInstancia().eliminarCliente(
									cliente);
						} catch (Exception e1) {
							e1.printStackTrace();
						}
						_volver();
					}
				});
			}
			{
				btnSalir = new JButton();
				getContentPane().add(btnSalir);
				btnSalir.setText("Salir");
				btnSalir.setBounds(386, 145, 97, 35);
				btnSalir.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						_volver();
					}
				});
			}
			{
				btnNuevaCond = new JButton();
				getContentPane().add(btnNuevaCond);
				btnNuevaCond.setText("Nueva Condicion");
				btnNuevaCond.setBounds(362, 191, 121, 35);
				
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Ver Facturas");
				jButton2.setBounds(386, 269, 97, 35);
				/*
				 * jButton2.addActionListener(new ActionListener() { public void
				 * actionPerformed(ActionEvent evt) { AdministrarFacturas frm =
				 * new AdministrarFacturas( cliente);
				 * frm.setLocationRelativeTo(null); frm.setVisible(true); } });
				 */
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void setData() {
		if (this.cliente != null) {
			jTextIVA.setText(cliente.getCondicionIva() + "");
			JTextRS.setText(cliente.getRazonSocial());
			jTextCuil.setText(cliente.getCuil());
		}
	}

	protected void deshabilitarCampos() {
		for (Component c : getContentPane().getComponents()) {
			if (c.getClass().equals(JTextField.class)) {
				JTextField jt = (JTextField) c;
				jt.disable();
			}
		}
	}

	protected void _exit() {
		this.dispose();
	}

	protected void _volver() {
		AdministrarClientes adm = new AdministrarClientes();
		adm.setLocationRelativeTo(null);
		adm.setVisible(true);
		_exit();
	}

	private void jButton1ActionPerformed(ActionEvent evt) {
		System.out.println("jButton1.actionPerformed, event=" + evt);
		// TODO add your code for jButton1.actionPerformed
	}

	private void jButton2ActionPerformed(ActionEvent evt) {
		System.out.println("jButton2.actionPerformed, event=" + evt);
		// TODO add your code for jButton2.actionPerformed
	}

}
